home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / js / treeView.js < prev    next >
Text File  |  2010-05-19  |  18KB  |  1 lines

  1. var treeFoldAnimSteps=10;var treeViews={};var treeSelectedNode={};var treeTmpSelectedNode=0;var treeTmpBottomNode=0;var treeProcessing=false;var blockIfTreeProcessing=false;var TVDebug=0,TVDebugCount=0;var IE6SyncWA=0;function treeView(b,a){this.name=b;this.tree=a;this.selectedNode=false;this.draggableNodes=0;this.receiverOnlyNodes=0;this.selectFunction=0;this.dblClickFunction=0;this.initialized=0;this.selectOnUpdate=0;this.offsetHeight=0;this.outerDiv;this.div;this.sync="auto"}treeView.prototype.init=function(){var b=treeEmptyNode(this.name,this.tree.path,1);b.setAttribute("name",this.name);var a=new treeNode(b);a.update(this.tree);this.outerDiv=dgi(this.name+"_outer");this.div=a.node;b.setAttribute("class","treeView");b.setAttribute("className","treeView");dgi(this.name).appendChild(b);if(treeTmpSelectedNode){treeTmpSelectedNode.setSelected()}treeTmpSelectedNode=0;treeTmpBottomNode=0;this.initialized=1};treeView.prototype.reset=function(a){this.tree=a;var b=new treeNode(this.name+"_"+this.tree.path);b.node.parentNode.removeChild(b.node);this.init()};treeView.prototype.firstChild=function(){return this.baseNode().firstChild()};treeView.prototype.baseNode=function(){return new treeNode(this.div)};treeView.prototype.update=function(a,c){if(TVDebug&&!dgi(this.name+"_"+a.path)){alert("treeView update error : inexisting id "+this.name+"_"+a.path)}var b=new treeNode(this.name+"_"+a.path);if(TVDebug){alert("UPDATE --- \n"+((b)?"":"NULL node !")+treeToString(a,0,a.path))}b.update(a);if(treeTmpBottomNode&&treeTmpBottomNode.parentNode()){treeTmpBottomNode.parentNode().unfold()}if(a.selected==undefined){b.unfold()}if(c&&treeTmpSelectedNode){treeTmpSelectedNode.setSelected()}if(this.selectOnUpdate){this.selectOnUpdate.select()}this.selectOnUpdate=0;treeTmpSelectedNode=0;treeTmpBottomNode=0};treeView.prototype.setSelectedNode=function(a){this.selectedNode=a};treeView.prototype.selectedNode=function(){return this.selectedNode};treeView.prototype.setSelectOnUpdate=function(a){this.selectOnUpdate=a};treeView.prototype.setSelectFunction=function(a){this.selectFunction=a;if(a==treeSyncSelectPath){IE6SyncWA=1}};treeView.prototype.setDblClickFunction=function(a){this.dblClickFunction=a};treeView.prototype.setRightClickFunction=function(a){this.rightClickFunction=a};treeView.prototype.setToggleFoldFunction=function(a){this.toggleFoldFunction=a};treeView.prototype.adjustInnerDiv=function(){alignBottom(dgi(this.name),dgi(this.name+"_outer"),2)};function treeNode(b,a){if(typeof(b)=="string"){b=dgi(b)}this.node=b;this.id=b.id;if(a){alert(this.id)}}function treeNodeChecked(a){if(typeof(a)=="string"){a=dgi(a)}if(!a||!a.id){return false}for(elem in treeViews){if(a.id.substr(0,elem.length+1)==elem+"_"){return new treeNode(a)}}return false}treeNode.prototype.treeView=function(){return treeViews[this.id.substr(0,this.id.indexOf("_"))]};treeNode.prototype.isRoot=function(){if(nameAttribute(this.node)){return true}else{return false}};treeNode.prototype.update=function(p,b){var l=false,v=false,o=false,w,u,h,d=false,j=false;if(b===undefined){var f=1;b=0}var q=p.path;if(TVDebug){alert("START UPDATE OF "+q)}var z=q.substr(q.lastIndexOf("/")+1);if(p.id){this.setExtId(p.id)}if(p.ico){this.setIconSrc((p.ico.substr(0,1)=="/")?p.ico:"/gfx/fi/"+p.ico)}else{this.setIconSrc(treeIconFolder)}if(p.label==undefined){label=z}else{label=p.label}this.setLabel(label);if(this.isRoot()){if(!label){this.hideNode(1)}this.label().setAttribute("class","treeRootLabel");this.label().setAttribute("className","treeRootLabel")}if(p.selected!=undefined&&!treeTmpSelectedNode){treeTmpSelectedNode=this}if(p.faded){this.setFaded()}if(p.sub===false){d=false}else{d=count(p.sub)}var y=this.childrenNodesIds();if(!d&&y!==null){d=Math.max(count(y),d)}if(y===null&&(d||q=="computerRoot"||q=="*resourceBasePath*")){l=document.createElement("div");l.setAttribute("name","sub");l.setAttribute("class","subTree tn"+b);l.setAttribute("className","subTree tn"+b);if(this.treeView().initialized){this.node.className="treeFolded"}o=1}else{l=this.subNodeDiv()}if(this.isRoot()){l.style.marginLeft="-12px"}var k;if(TVDebug){alert("COMPARE  \n"+arrayToString(p.sub)+" AND\n"+arrayToString(y))}for(arrayDir in p.sub){for(v in y){if(v==arrayDir){if(TVDebug&&b==0){alert("DELETE "+arrayDir+" from "+q)}if(count(p.sub[arrayDir]["sub"])){if(TVDebug){alert("go to update subnode "+arrayDir+" from "+q)}if(q=="computerRoot"){p.sub[arrayDir]["path"]=arrayDir}else{p.sub[arrayDir]["path"]=q+"/"+arrayDir}j=arrayDir;this.childNode(arrayDir).update(p.sub[arrayDir],b+1);arrayDir=j}else{if(TVDebug){alert("NO update of subnode "+arrayDir+" from "+q)}}delete (p.sub[arrayDir]);delete (y[arrayDir]);if(TVDebug){alert("DELETE "+arrayDir+" from "+q)}break}}}if(TVDebug){alert("Pre-remove subDirs "+arrayToString(y)+" from "+q)}for(v in y){if(TVDebug){alert("REMOVE subnode "+y[v]+" from "+q)}l.removeChild(dgi(y[v]))}var m=0,a,c;var n=this.treeView().receiverOnlyNodes;var x=this.treeView().name;var s=(this.treeView().dblClickFunction)?1:0;var g=(this.treeView().rightClickFunction)?1:0;var r=dgi(x+"_outer");for(arrayDir in p.sub){a=p.sub[arrayDir];if(m++==0){y=this.childrenNodesIds()}w=false;for(v in y){if(v.toLowerCase()>arrayDir.toLowerCase()){w=v;break}}if(q=="computerRoot"){h=arrayDir}else{h=q+"/"+arrayDir}c={};if(a.disabled){c.disabled=1}if(a.faded){c.faded=1}if(a.action){c.action=a.action}u=treeEmptyNode(x,h,s,g,a.tag,c);if(n){drec.addElt(u);drec.addTimeoutFunc(u,'new treeNode("'+u.id+'").unfold()',treeOpenTimeout);drec.setScrollContainer(u,r)}a.path=h;tmpNode=new treeNode(u);if(TVDebug){alert("insert "+h+" into "+q)}tmpNode.update(a,b+1);if(w){l.insertBefore(u,dgi(y[v]))}else{l.appendChild(u)}}if(!this.isRoot()){if(d===false){this.setFolded();if(TVDebug){alert("update "+q+" folded")}}else{if(d){if(p.unfolded){this.setUnfolded();if(TVDebug){alert("update "+q+" unfolded")}}}else{this.setEmpty();if(TVDebug){alert("update "+q+" empty")}}}if(p.bottom){treeTmpBottomNode=this}}else{this.setEmpty();if(TVDebug){alert("update "+q+" empty2")}}if(o){this.node.appendChild(l)}treeProcessing=false;if(TVDebug){alert("END UPDATE OF "+q)}};treeNode.prototype.parentNode=function(){if(this.isRoot()||!this.node.parentNode){return false}return new treeNode(this.node.parentNode.parentNode)};treeNode.prototype.childNode=function(a){return new treeNode(dgi(this.id+"/"+a))};treeNode.prototype.firstChild=function(){var a=this.subNodeDiv().childNodes;if(!a||!a[0]){return false}return new treeNode(a[0].id)};treeNode.prototype.nextSibling=function(){var b=this.parentNode().subNodeDiv().childNodes;if(!b){return false}var a=0;for(var c in b){if(a&&b[c]["id"]){return new treeNode(b[c]["id"])}if(b[c]["id"]==this.id){a=1}}};treeNode.prototype.previousSibling=function(){var a,b=this.parentNode().subNodeDiv().childNodes;if(!b){return false}for(a=1;a<b.length;a++){if(a>1&&b[a]["id"]==this.id){return new treeNode(b[a-1]["id"])}}};treeNode.prototype.handle=function(){return this.node.firstChild};treeNode.prototype.setHandleSrc=function(a){this.node.firstChild.setAttribute("src",a)};treeNode.prototype.label=function(){return this.node.firstChild.nextSibling.firstChild.nextSibling};treeNode.prototype.getLabel=function(){return this.node.firstChild.nextSibling.firstChild.nextSibling.innerHTML};treeNode.prototype.setLabel=function(a){this.node.firstChild.nextSibling.firstChild.nextSibling.innerHTML=a};treeNode.prototype.tag=function(){return this.node.getAttribute("alt")};treeNode.prototype.setTag=function(a){this.node.setAttribute("alt",a)};treeNode.prototype.setFaded=function(){setAlpha(this.node,0.5)};treeNode.prototype.icon=function(){if(!this.node.firstChild){alert("Treview error")}return this.node.firstChild.nextSibling.firstChild};treeNode.prototype.setIconSrc=function(a){var b=this.node.firstChild.nextSibling.firstChild;if(a){b.setAttribute("src",a)}else{b.style.display="none"}};treeNode.prototype.setExtId=function(a){this.node.setAttribute("extId",a)};treeNode.prototype.getExtId=function(a){return this.node.getAttribute("extId")};treeNode.prototype.subNodeDiv=function(){if(this.node.firstChild.nextSibling.nextSibling){return this.node.firstChild.nextSibling.nextSibling}else{return false}};treeNode.prototype.treeName=function(){return this.id.substr(0,this.id.indexOf("_"))};treeNode.prototype.getPath=function(){return this.id.substr(this.id.indexOf("_")+1)};treeNode.prototype.hideNode=function(a){this.handle().style.display="none";this.node.firstChild.nextSibling.style.display="none";if(!a&&this.subNodeDiv()){this.subNodeDiv().style.display="none"}};treeNode.prototype.showNode=function(){var a;this.handle().style.display="";this.node.firstChild.nextSibling.style.display="";if(a=this.subNodeDiv()){a.style.display="";$(a).e.setAlpha(1)}};treeNode.prototype.setLoading=function(){this.setHandleSrc(treeIconLoading);this.handle().onmouseover=function(){};this.handle().onmouseout=function(){}};treeNode.prototype.isSelected=function(){return this.treeView().selectedNode.id==this.id};treeNode.prototype.isFolded=function(){return this.node.className.indexOf("treeFolded")!=-1};treeNode.prototype.setFolded=function(){this.node.className="treeFolded";this.setHandleSrc(treeIconPlus);if(treeIconPlusOver){this.handle().onmouseover=function(){this.src=treeIconPlusOver};this.handle().onmouseout=function(){this.src=treeIconPlus}}if(this.treeView().initialized&&this.treeView().toggleFoldFunction){this.treeView().toggleFoldFunction(this)}};treeNode.prototype.focusView=function(){var b=this.node.offsetTop,a=this.treeView().outerDiv;if(b<a.scrollTop||b>a.scrollTop+a.offsetHeight){a.scrollTop=b-(a.offsetHeight/8)}};treeNode.prototype.setUnfolded=function(){var sND;if(this.isRoot()){return}if(this.node.className=="treeUnfolded"){return}iconSrc=this.icon().src.toLowerCase();iconSrc=iconSrc.substr(iconSrc.length-treeIconFolder.length);if(iconSrc==treeIconFolder.toLowerCase()){this.setIconSrc(treeIconFolderO)}this.node.className="treeUnfolded";if(sND=this.subNodeDiv()){with(sND.style){display="";overflow="";height=""}$(sND).e.setAlpha(1)}this.setHandleSrc(treeIconMinus);if(treeIconMinusOver){this.handle().onmouseover=function(){this.src=treeIconMinusOver};this.handle().onmouseout=function(){this.src=treeIconMinus}}if(this.treeView().initialized&&this.treeView().toggleFoldFunction){this.treeView().toggleFoldFunction(this)}};treeNode.prototype.toggleFold=function(){if(this.isFolded()){this.setUnfolded()}else{this.setFolded()}};treeNode.prototype.toggleFoldAnim=function(){if(this.isFolded()){this.unfold()}else{this.fold()}};treeNode.prototype.setEmpty=function(){if(this.isRoot()){this.handle().style.display="none";return}this.node.className="treeEmpty";this.setHandleSrc("/gfx/vl.gif");this.handle().onmouseover=null;this.handle().onmouseout=null};treeNode.prototype.childrenNodesIds=function(){var d=this.subNodeDiv();if(!d){return null}var b=d.childNodes;var a={};var c;for(i=0;i<b.length;i++){c=b[i].getAttribute("id");if(c.lastIndexOf("/")==-1){a[c.substr(c.indexOf("_")+1)]=c}else{a[c.substr(c.lastIndexOf("/")+1)]=c}}return a};treeNode.prototype.childrenNodes=function(){if(!this.subNodeDiv()){return null}return this.subNodeDiv().childNodes};treeNode.prototype.unfold=function(){if(this.isFolded()){children=this.childrenNodesIds();if(children===null){if(treeProcessing&&blockIfTreeProcessing){return}treeProcessing=true;this.setLoading();var c=document.comForm.data1.value;D.comForm.data1.value=this.getPath();fillAndSubmit("","treeUnfoldTo",this.treeView().name,this.id,true);D.comForm.data1.value=c}else{this.setUnfolded();var b=this.subNodeDiv().style;b.display="";b.overflow="hidden";b.height="0px";var a=(actualOffsetTop(this.subNodeDiv().lastChild)-actualOffsetTop(this.subNodeDiv().firstChild)+this.subNodeDiv().firstChild.offsetHeight);treeNodeFoldAnim(this.id,1,0,a)}}if(this.parentNode()&&this.parentNode().isFolded()){this.parentNode().unfold()}};treeNode.prototype.fold=function(){if(!this.subNodeDiv()){return}var a=this.subNodeDiv().offsetHeight;this.subNodeDiv().style.overflow="hidden";treeNodeFoldAnim(this.id,-1,undefined,a)};function treeNodeFoldAnim(f,b,c,d){var a=new treeNode(f);if(b==1){wl.anim({item:a.subNodeDiv(),duration:Math.min(700,3*d),extraParams:{baseH:d,treeNode:a},"function":function(j,h){var g=wl.animFunctionUnfold2(j,h);return{height:Math.max(1,g*h.extraParams.baseH),opacity:(phpBrowser=="ie")?1:Math.min(1.2*g,1)}},callbackComplete:function(h){var g=h.extraParams.treeNode;h.item.style.height="";g.setUnfolded();if(g.treeView().receiverOnlyNodes){drec.computeRect()}}})}else{wl.anim({item:a.subNodeDiv(),duration:Math.min(700,3*d),extraParams:{baseH:d,treeNode:a},"function":function(j,h){var g=wl.animFunctionFold2(j,h);return{height:Math.max(1,g*h.extraParams.baseH),opacity:(phpBrowser=="ie")?1:Math.min(1.5*g,1)}},callbackComplete:function(h){var g=h.extraParams.treeNode;g.setFolded();if(g.treeView().receiverOnlyNodes){drec.computeRect()}}})}}function tmp(g,b,c,f){var a=new treeNode(g);if(b==-1){var d=Math.floor(treeFoldAnimSteps*a.childrenNodes().length/10);d=Math.min(treeFoldAnimSteps,Math.max(1,d));if(c==undefined){c=d}c--;if(c==0){a.setFolded();if(a.treeView().receiverOnlyNodes){drec.computeRect()}}else{a.subNodeDiv().style.height=f*c/d;setTimeout('treeNodeFoldAnim("'+g+'","'+b+'","'+c+'","'+f+'")',1)}}else{c++;var d=Math.floor(treeFoldAnimSteps*a.childrenNodes().length/10);d=Math.min(treeFoldAnimSteps,Math.max(1,d));if(c==d){a.subNodeDiv().style.height="";a.setUnfolded();if(a.treeView().receiverOnlyNodes){drec.computeRect()}}else{a.subNodeDiv().style.height=f*c/d;setTimeout('treeNodeFoldAnim("'+g+'","'+b+'","'+c+'","'+f+'")',1)}}}treeNode.prototype.select=function(a){if(!treeUnfoldOnSelect&&this.isSelected()&&!this.isRoot()){if(this.isFolded()){this.unfold()}else{this.fold()}}if(treeProcessing){if(!blockIfTreeProcessing){this.treeView().setSelectOnUpdate(this)}return}if(treeUnfoldOnSelect&&!this.isFolded()&&!this.isRoot()&&this.subNodeDiv()){this.fold();return}this.setSelected();var b=this.treeView().sync;if(a){return}treeProcessing=1;goDirect(this.id.substr(this.id.indexOf("_")+1),(b=="auto")?false:b);if(treeUnfoldOnSelect&&this.isFolded()){this.unfold()}};treeNode.prototype.setSelected=function(){var b;var a=this.treeView().selectedNode;while(a){$(a.node.firstChild.nextSibling).e.className().remove("selected");b=a.icon().src.toLowerCase();b=b.substr(b.length-treeIconFolderO.length);if(b==treeIconFolderO.toLowerCase()){a.setIconSrc(treeIconFolder)}a=a.parentNode()}this.treeView().setSelectedNode(this);$(this.node.firstChild.nextSibling).e.className().add("selected");var c=this;while(1){if(!(c=c.parentNode())){break}c.setUnfolded()}};treeNode.prototype.setError=function(){this.setHandleSrc(treeIconError)};treeNode.prototype.setDraggable=function(){dragItem=this.id+NO_DRAG+CURSOR_HAND+RECEIVER;if(dd.ie){try{ADD_DHTML(dragItem)}catch(a){}}else{ADD_DHTML(dragItem)}};treeNode.prototype.remove=function(){removeNode(this.node)};function treeToggleFold(b){var a=new treeNode(b);if(a.isFolded()){a.unfold()}else{a.fold()}}function treeToggleFrame(){fillAndSubmit(true,"toggleTreeFrame",0,false,"sync")}function treeSelect(c,a){var b=new treeNode(c);if(b.treeView().selectFunction){b.treeView().selectFunction(b)}else{b.select(a)}}function treeDblClickF(b){var a=new treeNode(b);if(a.treeView().dblClickFunction){a.treeView().dblClickFunction(a)}}function treeRightClickF(b,c){var a=new treeNode(c);a.treeView().rightClickFunction(a);if(b.stopPropagation){b.stopPropagation()}else{b.cancelBubble=true}return false}function treeSyncSelectPath(a){goDirect(this.id.substr(this.id.indexOf("_")+1),"sync")}function treeEmptyNode(f,g,h,b,a,d){if(!d){d={}}var c=(!d.disabled),j=document.createElement("div");j.setAttribute("id",f+"_"+g);j.setAttribute("class","treeFolded");j.setAttribute("className","treeFolded");if(a){j.setAttribute("alt",a)}ih='<img src="'+treeIconPlus+'" class="treeHandle"'+((c)?'onclick="treeToggleFold(this.parentNode)"':"");if(c&&treeIconPlusOver){ih+=" onmouseover=\"this.src='"+treeIconPlusOver+"'\" onmouseout=\"this.src='"+treeIconPlus+"'\""}ih+="/>";if(!c){ih+="<i "}else{ih+="<a href=\"javascript:treeSelect(dgi('"+f+"_"+g.replace(new RegExp("'","g"),"\\'")+"')"+((d.action)?",1);"+d.action:")")+'"';if(h){ih+='ondblclick="treeDblClickF(this.parentNode)"'}if(b){ih+='oncontextmenu="return treeRightClickF(event,this.parentNode)"'}if(d.faded){ih+=' class="treeFaded"'}}ih+='><img src="'+treeIconFolder+'" class="treeIcon"'+((c&&!d.faded)?"":' style="filter:Alpha(opacity=20, style=0);opacity:0.2"')+"><span></span>\n";ih+=(c)?"</a>":"</i>";j.innerHTML=ih;return j}function treeMonitorHeight(){for(t in treeViews){with(treeViews[t]){if(treeViews[t].outerDiv&&Math.abs(offsetHeight-outerDiv.offsetHeight)>3){offsetHeight=outerDiv.offsetHeight;adjustInnerDiv()}}}}function treeToString(a,f,c){if(f==undefined){f=0}if(c==undefined){label="???"}else{label=c}if(a.label!=undefined){label=a.label}else{if(c==undefined){label="???"}else{label=c}}var b=" ";for(var d=0;d<f;d++){b+="    "}output=b+label+" - ";for(elem in a){if(elem!="label"&&elem!="sub"){output+="#"+elem+":"+a[elem]}}output+="\n";if(a.sub!==false){for(sdir in a.sub){output+=treeToString(a.sub[sdir],f+1,sdir)}}return output}function nameAttribute(a){if(phpBrowser=="ie"){return a.name}if(!a.hasAttribute("name")){return undefined}else{return a.getAttribute("name")}}function arrayToString(a){var b="";for(e in a){b+=e+" => "+a[e]+"\n"}return b}function treeFolderDblClickSelect(a){if(a.isFolded()){a.unfold()}}setInterval("treeMonitorHeight()",100);